<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title></title>
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../css/list.css" />
	<style>
		body {
			display: -webkit-box;
			-webkit-box-orient: vertical;
			background-color: #F9F9F9;
		}

		.clearfix:after {
			content: '';
			display: block;
			clear: both;
		}

		.btn-group {
			margin-top: 0.75em;
		}

		.btn-box-left {
			width: 49%;
		}

		.btn-box-right {
			width: 20%;
		}

		.btnGo {
			display: block;
			height: 37px;
			border-radius: 6px;
			line-height: 37px;
			text-align: center;
		}

		.log {
			background: url(../image/button_red_bg_nor.png) center center no-repeat;
			background-size: 100% 100%;
			border: 1px solid #3A8B7A;
			color: #FFF;
		}

		.log:active,
		.log.tap-active {
			background: url(../image/button_red_bg_press.png) center center no-repeat;
			background-size: 100% 100%;
		}

		.reg {
			background: url(../image/button_white_bg_nor.png) center center no-repeat;
			background-size: 100% 100%;
			border: 1px solid #C8C8C8;
			color: #909090;
		}

		.reg:active,
		.reg.tap-active {
			background: url(../image/button_white_bg_pressed.png) center center no-repeat;
			background-size: 100% 100%;
		}

		.pull-left {
			float: left;
		}

		.pull-right {
			float: right;
		}

		.input-wrap {
			padding: 20px 10px 0;
		}

		.input-wrap {
			padding: 20px 10px;
			position: relative;
		}

		.txt {
			border: 1px solid #e6e6e6;
			border-radius: 6px;
			padding: 10px;
			width: 75%;
			outline: none;
			-webkit-box-sizing: border-box;
			box-sizing: border-box;
		}

		.y_tbl {
			width: 100%;
			margin: 15px 0;
			padding-top: 3px;
			text-align: center;
			background: #E5E5E5;
		}

		.y_tbl td {
			border: solid 1px #6F6C6C;
		}

		.tdcontent a {
			text-decoration: none;
			color: red;
		}

		.starspantextc img {
			width: 15px;
		}
	</style>
</head>

<body>
	<div class="input-wrap">
		<input type="text" placeholder="请输入搜索关键字" class="txt" id="keyWord" value="" />
		<div class="btn-box-right pull-right">
			<a class="btnGo log" tapmode="tap-active" onclick="goto_loadDataFun()">搜索</a>
		</div>
	</div>
	<div class="h10" style="background-color: #F9F9F9;"></div>
	<div id="main_content" style="background-color: #F9F9F9;"></div>
	<div id="divNoDataTip" style="background-color: #F9F9F9;">
		<div id="textTip" style="margin-top:10px;margin-bottom:10px;width:100%;text-align: center;" class="button red" tapmode=""></div>
	</div>
	<div class="h10" style="background-color: #F9F9F9;"></div>
	<input id="pageIndex" type="hidden" value="0" />
	<input id="pageSize" type="hidden" value="20" />
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/alpenlicebe.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hashes.min.js"></script>
<script type="text/javascript" src="../script/raty/demo/js/jquery.min.js"></script>
<script type="text/javascript" src="../script/raty/lib/jquery.raty.min.js"></script>
<script>
	apiready = function() {
		/*下拉刷新*/
		api.setRefreshHeaderInfo({
			visible: true,
			loadingImg: 'widget://image/refresh.png',
			bgColor: '#fff',
			textColor: '#000',
			textDown: '下拉刷新...',
			textUp: '松开刷新...',
			showTime: true
		}, function(ret, err) {
			$("#pageIndex").val(0);
			$("#main_content").html("");
			$("#textTip").html("正在加载..");
			goto_loadDataFun();
			api.refreshHeaderLoadDone();
		});
		goto_loadDataFun();

	}


	function goto_loadDataFun() {
		$("#pageIndex").val(0);
		$("#main_content").html("");


		/*滑动到底部加载数据*/
		api.addEventListener({
			name: 'scrolltobottom'
		}, function(ret, err) {
			goto_loadNewsListFun();
		});
		goto_loadNewsListFun();
		api.parseTapmode();
	}

	function goto_loadNewsListFun() {
		var userID = Alpe_getLocalStorge('access_token');
		if ('' == userID) {
			api.alert({
				title: '系统提示',
				msg: '您未登录'
			});
			return;
		}
		var keyWord = $api.byId('keyWord').value;
		var pageIndex = parseInt($("#pageIndex").val()) + 1;
		var pageSize = $("#pageSize").val();
		$("#pageIndex").val(pageIndex);

		api.showProgress({
			style: 'default',
			animationType: 'fade',
			title: '',
			text: '',
			modal: false
		});

		var MD5 = new Hashes.MD5;
		var access_token = Alpe_getLocalStorge("access_token");
		var admin_id = Alpe_getLocalStorge("admin_id");
		var sign = MD5.hex(access_token + admin_id + pageIndex + 'datas/getMsglist' + keyWord + '1.0syjqingbao');

		var url = Alpe_ApiUrl + 'r=datas/getMsglistAll&access_token=' + access_token + '&admin_id=' + admin_id +
			'&page=' + pageIndex + '&deal_status=-1&search_str=' + keyWord +
			'&v=1.0&sign=' + sign;
			console.log(url);
		api.ajax({
			url: url,
			method: 'get',
			cache: false,
			timeout: 30,
			dataType: 'json'
		}, function(ret, err) {
			if (ret) {
				if (ret.success == '100') {
					$.each(ret.msgdatalist, function(index, v) {
						var suggestion = v.suggestion.replace(/\n/g, "<br>");
						var style = "#333";
						if (v.is_read == 1) {
							style = "#919193";
						}
						var tmpHtml = '<div class="main_content" data-id="' + index + '" tapmode="presshover"><div class="cnt"><div class="wrap"><div class="wrap2"><div class="content"><div id="tit_' + v.message_id + '" onclick="goto_openDetailWinFun(' + v.message_id +
							')" class="shopname" style="color:' + style +
							';">' + v.title + '</div>';
						if (v.suggestion_array.length > 0) {
							tmpHtml += '<div><table class="y_tbl">' +
								'<tr>' +
								'<td style="width:90px"><b>时间</b></td>' +
								'<td style="width:70px"><b>状态</b></td>' +
								'<td><b>详情</b></td>' +
								'</tr>';
							$.each(v.suggestion_array, function(i, m) {

								var str = m.status;
								var display = 'none';
								if (i == v.suggestion_array.length - 1) {
									display = '';
								}
								if (m.is_copy ==1) {
									tmpHtml += '<tr class="deallisttr ' + display + '" style="display:' + display + '">' +
										// '<input type="hidden" value="'+m.img_path+'" />'+
										'<td>' + m.time + '</td>' +
										'<td>' + m.status + '</td>' +
										'<td style="text-align:left;">' + '<input class="imgpath" type="hidden" value="' + m.img_path + '" /><div  id="' + v.message_id + 'copy' + i + '">' + m.content + '</div>' +
										'<div style="margin:10px;float:right"><span style="background:#3A8B7A;color:#fff;padding:4px 12px;font-size:12px;" onclick="longPress(\'' +
										v.message_id + 'copy' + i + '\');">复制<span/></div>' + '</td>' +
										'</tr>';

								} else {
									tmpHtml += '<tr class="deallisttr ' + display + '" style="display:' + display + '">' +
										'<td>' + m.time + '</td>' +
										'<td>' + m.status + '</td>' +
										'<td style="text-align:left;">' + m.content + '</td>' +
										'</tr>';
								}

							});
							tmpHtml += '</table></div>';
						}
						if (v.suggestion_array.length > 1) {
							tmpHtml += '<div class="zhankaitr" style="color:blue;float:right;font-size:14px;padding-bottom:10px;" onclick="gotozhankai(this);" lang="0">全部记录</div>';
						}
						tmpHtml += '<div class="info"  style="clear:both;"><a class="symbol">' + v.media_name +
							'</a><a class="price">' + v.send_time + '</a></div></div></div></div></div></div>';
						$("#main_content").append(tmpHtml);
					});
				} else if ("002" == ret.success || "003" == ret.success) {
					goto_openWin_loginWin(ret.message);
				} else {
					api.removeEventListener({
						name: 'scrolltobottom'
					});
					$("#textTip").html(ret.message);
					api.toast({
						msg: ret.message,
						duration: 2000,
						location: 'middle'
					});
				}
				api.hideProgress();
			} else {
				api.alert({
					title: '系统提示',
					msg: '错误码：' + err.code + '；错误信息：' + err.msg + '网络状态码：' + err.statusCode
				});
				api.hideProgress();
			}
		});
	}

	function gotozhankai(obj, event) {
		stopBubbling(event);
		var lang = $(obj).attr('lang');
		if (lang == 0) {
			$(obj).parents('.main_content').find('.y_tbl').find('.none').show();
			$(obj).attr('lang', '1');
			$(obj).html('最新记录');
		}

		if (lang == 1) {
			$(obj).parents('.main_content').find('.y_tbl').find('.none').hide();
			$(obj).attr('lang', '0');
			$(obj).html('全部记录');

			var index = $(obj).parents('.main_content').attr("data-id");
			// alert(index);
			var TotalTrheight = getTotalTrheight(index);
			$(window).scrollTop(TotalTrheight);
		}

	}

	function gotoImage(obj, event) {
		stopBubbling(event);
		var imgpath = $(obj).parents('td').find('.imgpath').val();
		var strs = new Array(); //定义一数组
		strs = imgpath.split("|"); //字符分割
		var obj = api.require('imageBrowser');
		obj.openImages({
			imageUrls: strs,
			showList: false,
			activeIndex: 0
		});
	}
	//	复制功能
	function longPress(message_id, event) {
		stopBubbling(event);
		var copytext = $("#" + message_id).text();
		var clipBoard = api.require('clipBoard');
		clipBoard.set({
			value: copytext
		}, function(ret, err) {
			if (ret) {
				api.toast({
					msg: '复制成功',
					duration: 1500,
					location: 'bottom',
					global: true
				});
			} else {

			}
		});
		return false;
	}

	function stopBubbling(e) {
		e = window.event || e;
		if (e.stopPropagation) {
			e.stopPropagation(); //阻止事件 冒泡传播
		} else {
			e.cancelBubble = true; //ie兼容
		}
	}

	function init() {

		var len = 78; //默认显示字数
		var content = "";
		var html = "";
		$(".tdcontent").each(function() {
			content = $(this).html();
			// alert($(this).scrollTop());
			html = '<span class="allstr" style="display:none;">' + content + '</span>';
			html += '<span class="substr" >' + content.substring(0, len) + '</span>';
			if (content.length > len) {
				html += '<a class="zhedie" href="javascript:void(0)" onclick="openAllcontent(this);" >... 展开</a>';
			}
			$(this).html('');
			$(this).html(html);
		});

	}

	//计算之前所有div块的高度
	function getTotalTrheight(index) {
		var totalTrheight = 0;
		var trheight = 0;
		$(".main_content").each(function() {
			var num = $(this).attr("data-id");
			trheight = $(this).height();
			if (num < index) {
				totalTrheight = totalTrheight + parseInt(trheight);
			}
		});
		return totalTrheight;
	}

	function openAllcontent(obj) {

		if ($(obj).html().indexOf("展开") > 0) {
			$(obj).html("<<&nbsp;收起");
			$(obj).parent().find(".allstr").show();
			$(obj).parent().find(".substr").hide();
		} else {
			var index = $(obj).parents('.main_content').attr("data-id");
			// alert(index);
			var TotalTrheight = getTotalTrheight(index);
			$(obj).html("... 展开");
			$(window).scrollTop(TotalTrheight);
			$(obj).parent().find(".substr").show();
			$(obj).parent().find(".allstr").hide();
		}
	}

	function goto_openDetailWinFun(infoID) {
		var delay = 0;
		if ("ios" != api.systemType) {
			delay = 300;
		}
		api.openWin({
			name: 'yq_listDetail',
			url: './yq_listDetail.html',
			bounces: false,
			reload: true,
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			pageParam: {
				infoID: infoID,
				is_button:0
			},
			delay: delay
		});
	}
</script>

</html>
